home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / Text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  8.0 KB  |  246 lines

  1. /*
  2.  * (c) Copyright 1995, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  * Permission to use, copy, modify, and distribute this software for
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * US Government Users Restricted Rights
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * Author: John Spitzer, SGI Applied Engineering
  36.  *
  37.  */
  38. #include <math.h>
  39. #include "Global.h"
  40. #include "Text.h"
  41. #include "TextX.h"
  42.  
  43. #undef offset
  44. #define offset(v) offsetof(Text, v)
  45.  
  46. static InfoItem TextInfo[] = {
  47. #define INC_REASON INFO_ITEM_ARRAY
  48. #include "Text.h"
  49. #undef INC_REASON
  50. };
  51. #include <malloc.h>
  52.  
  53. TextPtr new_Text()
  54. {
  55.     TextPtr this = (TextPtr)malloc(sizeof(Text));
  56.  
  57.     CheckMalloc(this);
  58.     new_RasterPos((RasterPosPtr)this);
  59.     SetDefaults((TestPtr)this, TextInfo);
  60.     this->testType = TextTest;
  61.     this->traversalData = 0;
  62.     this->subImageData = 0;
  63.     this->imageData = 0;
  64.     this->usecPixelPrint = " microseconds per pixel with Text";
  65.     this->ratePixelPrint = " pixels per second with Text";
  66.     this->usecPrint = " microseconds per Text character";
  67.     this->ratePrint = " Text characters per second";
  68.     /* Set virtual functions */
  69.     this->SetState = Text__SetState;
  70.     this->delete = delete_Text;
  71.     this->Copy = Text__Copy;
  72.     this->Initialize = Text__Initialize;
  73.     this->Cleanup = Text__Cleanup;
  74.     this->SetExecuteFunc = Text__SetExecuteFunc;
  75.     this->PixelSize = Text__Size;
  76.     this->TimesRun = Text__TimesRun;
  77.     return this;
  78. }
  79.  
  80. void delete_Text(TestPtr thisTest)
  81. {
  82.     TextPtr this = (TextPtr)thisTest;
  83.  
  84.     delete_RasterPos(thisTest);
  85. }
  86.  
  87. TestPtr Text__Copy(TestPtr thisTest)
  88. {
  89.     TextPtr this = (TextPtr)thisTest;
  90.     TextPtr newText = new_Text();
  91.     FreeStrings((TestPtr)newText);
  92.     *newText = *this;
  93.     CopyStrings((TestPtr)newText, (TestPtr)this);
  94.     return (TestPtr)newText;
  95. }
  96.  
  97. void Text__Initialize(TestPtr thisTest)
  98. {
  99.     TextPtr this = (TextPtr)thisTest;
  100.     int windowDim = min(this->environ.windowWidth, this->environ.windowHeight);
  101.     int windowArea = windowDim * windowDim;
  102.     GLint *intTraversalData;
  103.     GLint *srcPtr;
  104.     GLfloat *dstPtr;
  105.     char* textPtr;
  106.     int i;
  107.     char* sampleString = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789";
  108.     int sizeSample = strlen(sampleString);
  109.  
  110.     /* Create String */
  111.     this->textString = (char*)malloc(this->charsPerString + 1);
  112.     textPtr = this->textString;
  113.     for (i = 0; i < this->charsPerString / sizeSample; i++) {
  114.     memcpy(textPtr, sampleString, sizeSample);
  115.     textPtr += sizeSample;
  116.     }
  117.     memcpy(textPtr, sampleString, this->charsPerString % sizeSample);
  118.     textPtr += this->charsPerString % sizeSample;
  119.     *textPtr = (char)0;
  120.  
  121.     TextFont__StringSize(this->textFont, this->textString,
  122.                          &this->textWidth, &this->textWidthPadding,
  123.                          &this->textHeight, &this->textHeightPadding);
  124.     /* Layout RasterPos coordinates */
  125.     this->numDrawn = 0;
  126.     intTraversalData = CreateSubImageData(windowDim, windowDim, 
  127.                           (float)this->textWidth, 
  128.                           (float)this->textHeight,
  129.                           this->acceptObjs, this->rejectObjs, this->clipObjs,
  130.                           this->clipMode, this->clipAmount, this->drawOrder==Spaced, 
  131.                           this->memAlignment, &this->numDrawn);
  132.  
  133.     /* Convert RasterPos coordinates to NDC */
  134.     this->traversalData = (GLfloat*)AlignMalloc(sizeof(GLfloat) * this->rasterPosDim * this->numDrawn, this->memAlignment);
  135.     srcPtr = intTraversalData;
  136.     dstPtr = this->traversalData;
  137.     for (i = 0; i < this->numDrawn; i++) {
  138.         *dstPtr++ = ((double)(*srcPtr++ + this->textWidthPadding) + .375) / (double)windowDim * 2. - 1.;
  139.         *dstPtr++ = ((double)(*srcPtr++ + this->textHeightPadding) + .375) / (double)windowDim * 2. - 1.;
  140.     }
  141.     AlignFree(intTraversalData);
  142.  
  143.     /* Add color and z coordinate if necessary */
  144.     RasterPos__AddTraversalData((RasterPosPtr)this);
  145.  
  146.     Text__CreateTextData(this);
  147. }
  148.  
  149. void Text__Cleanup(TestPtr thisTest)
  150. {
  151.     int i;
  152.  
  153.     TextPtr this = (TextPtr)thisTest;
  154.     void **imagePtr = this->imageData;
  155.     for ( i = 0; i < this->numObjects; i++) {
  156.       if(*imagePtr)
  157.     AlignFree(*imagePtr);
  158.       imagePtr++;
  159.     }
  160.     if(this->imageData)
  161.       free(this->imageData);
  162.  
  163.     if (this->traversalData) AlignFree(this->traversalData);
  164.     if (this->textString) free(this->textString);
  165.  
  166.     if (this->textFont) delete_TextFont(this->textFont);
  167. }
  168.  
  169. int Text__SetState(TestPtr thisTest)
  170. {
  171.     TextPtr this = (TextPtr)thisTest;
  172.  
  173.     /* set parent state */
  174.     if (RasterPos__SetState(thisTest) == -1) return -1;
  175.  
  176.     /* set own state */
  177.     if ((this->textFont = new_TextFont(this->charFont)) == 0) return -1;
  178.  
  179.     /* This routine doesn't support more than one level of unrolling */
  180.     if (this->loopUnroll > 1)
  181.         return -1;
  182.  
  183.     this->base = TextFont__GetBase(this->textFont);
  184.  
  185.     return 0;
  186. }
  187.  
  188. void Text__SetExecuteFunc(TestPtr thisTest)
  189. {
  190.     TextPtr this = (TextPtr)thisTest;
  191.     TextFunc function;
  192.  
  193.     function.word = 0;
  194.  
  195.     function.bits.functionPtrs = this->loopFuncPtrs;
  196.     function.bits.multiimage = (this->numObjects > 1);
  197.     function.bits.colorData = (this->colorData == PerRasterPos) ? PER_RASTERPOS : NONE;
  198.     function.bits.visual = this->environ.bufConfig.rgba ? RGB : CI;
  199.  
  200.     /* Dimensions of data to be traversed */
  201.     function.bits.rasterPosDim  = this->rasterPosDim - 2;
  202.     function.bits.colorDim = this->colorDim - 3;
  203.  
  204.     this->Execute = TextExecuteTable[function.word];
  205. }
  206.  
  207. int Text__TimesRun(TestPtr thisTest)
  208. {
  209.     TextPtr this = (TextPtr)thisTest;
  210.     return this->numDrawn*this->charsPerString;
  211. }
  212.  
  213. float Text__Size(TestPtr thisTest)
  214. {
  215.     TextPtr this = (TextPtr)thisTest;
  216.     int accept = this->acceptObjs * (float)(this->numDrawn);
  217.     int reject = this->rejectObjs * (float)(this->numDrawn);
  218.     int clip = this->clipObjs * (float)(this->numDrawn);
  219.     float size = (float)this->textWidth * (float)this->textHeight;
  220.     float acceptSize, clipSize;
  221.  
  222.     accept += this->numDrawn - accept - reject - clip;
  223.  
  224.     acceptSize = (float)accept * size;
  225.     clipSize = (float)clip * (1. - this->clipAmount) * size;
  226.  
  227.     return (acceptSize + clipSize)/(float)this->numDrawn;
  228. }
  229.  
  230. void Text__CreateTextData(TextPtr this)
  231. {
  232.     int i;
  233.     void **imagePtr;
  234.     int imageSize;
  235.  
  236.     this->imageData = (void**)malloc(sizeof(void*) * this->numObjects);
  237.     CheckMalloc(this->imageData);
  238.     imagePtr = this->imageData;
  239.  
  240.     for (i = 0; i < this->numObjects; i++) {
  241.     *imagePtr = AlignMalloc(this->charsPerString + 1, this->memAlignment);
  242.     strcpy(*imagePtr, this->textString);
  243.     imagePtr++;
  244.     }
  245. }
  246.